<script type="text/javascript" src="<?= base_url() . 'resource/js/layer/layer.js' ?>" charset="utf-8"></script>
<script type="text/javascript">
    $(function () {
        $("select[data-edit-select]").filterSelect();
    })
</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <h1><?=lang('menu_yhgl')?></h1>
      <?=$this->breadcrumb->generateHTML();?>
    </div>
  </div>
  <div class="container-fluid">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i><?=lang('menu_yhlb')?></h3>
      </div>
      <div class="panel-body">
        <div class="well" style="padding:0 19px;">
          <div class="row">
            <form action="<?= blang_url('users/member/') ?>" method="get" name="searchform">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label"><?= lang('member_zh') ?></label>
                        <input class="form-control" name="account" value="<?= $account ?>" placeholder="<?= lang('member_zh') ?>"/>
                    </div>
                    <div class="form-group">
                        <label class="control-label"><?= lang('member_zsxm') ?></label>
                         <input class="form-control" name="name" value="<?= $name ?>" placeholder="<?= lang('member_zsxm') ?>"/>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label"><?= lang('member_youxiang') ?></label>
                        <input class="form-control" name="email" value="<?= $email ?>" placeholder="<?= lang('member_youxiang') ?>"/>
                    </div>
                    <div class="form-group">
                        <label class="control-label"><?= lang('member_bm') ?></label>
                         <input class="form-control" name="position" value="<?= $position ?>" placeholder="<?= lang('member_bm') ?>"/>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label"><?= lang('member_zt') ?></label>
                        <select class="form-control" name="status" id="statusId">
                            <option value="">--<?= lang('member_zt') ?>--</option>
                            <option value="1" <?= $optStatus['1'] ?> >--<?= lang('member_qy') ?>--
                            </option>
                            <option value="0" <?= $optStatus['0'] ?>>--<?= lang('member_gb') ?>--
                            </option>
                        </select>
                    </div>
                    <input type="submit" class="btn btn-primary pull-right" name="searchSubmit" value="<?= lang('public_cx') ?> " />
                </div>
            </form>
            
          </div>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-hover oms-table" id="ct_content1">
              <thead>
                <tr>
                    <th class="text-left"><?= lang('member_zh') ?></th>
                    <th class="text-left"><?= lang('member_zsxm') ?></th>
                    <th class="text-left" style="width:10%;"><?= lang('member_jiaose') ?></th>
                    <th class="text-left"><?= lang('member_bm') ?></th>
                    <th class="text-right"><?= lang('member_youxiang') ?></th>
                    <th class="text-right"><?= lang('member_zt') ?></th>
                    <th class="text-right"><?= lang('member_wwqx') ?></th>
                    <th class="text-right"><?= lang('member_cz') ?></th>
                </tr>
              </thead>
              <tbody>
                <?php if ($dataList): foreach ($dataList as $key => $rs): ?>
                <tr>
                    <td class="text-left"><?= $rs['account'] ?></td>
                    <td class="text-left"><?= $rs['name'] ?></td>
                    <td class="text-left"><?= $rs['role'] ?></td>
                    <td class="text-left"><?= $rs['position'] ?></td>
                    <td class="text-right"><?= $rs['email'] ?></td>
                    <td class="text-right">
                        <a href="<?= blang_url('users/member/set_active/' . $rs['id'] . '/' . $rs['active'] . '/' . $page) ?>">
                            <?= $rs['active_as_name'] ?>
                        </a>
                    </td>
                    <td class="text-right">
                        <a href="<?= blang_url('users/member/set_isopen/' . $rs['id'] . '/' . $rs['is_open'] . '/' . $page) ?>">
                            <?= $rs['isopen_as_name'] ?>
                        </a>
                    </td>
                    <td class="text-right" align="center">
                        <!--<a class="btn btn-primary btn-sm" href="<? /*=blang_url('users/member/inDetails/'.$rs['id'].'/'.$page)*/ ?>" >查看详情</a>-->
                        <a class="btn btn-primary btn-sm edituser" href="javascript:void(0)" data-id="<?= $rs['id'] ?>"
                           data-role="<?= $rs['role_id']?>" data-join="<?=$rs['franchisees_id']?>" title="<?= lang('btnMdy') ?>"><i class="fa fa-edit"></i></a>
                        <a class="btn btn-danger btn-sm" href="<?= blang_url('users/member/del/' . $rs['id'] . '/' . $page) ?>"
                           onclick="return confirm('Sure you want to delete?')" title="<?= lang('btnDelete') ?>"><i class="fa fa-trash-o"></i></a>
                    </td>
                </tr>
                <?php endforeach; else:?>
                    <tr><th colspan="8" class="emptyNumber"><?=lang('public_mygdsj')?>....</th></tr>
                <?php endif; ?>
            </tbody>
            </table>
            <?php if($show_pages):?>
                <div class="page">
                    <?=$show_pages?>
                </div>
            <?php endif;?>
            
          </div>
      </div>
    </div>
    </div>

   <div class="mdyuser" style="display: none;">
        <div class="mdy_user_title">
            <label style="float:left;"><?= lang('tip_title') ?></label>
            <a href="#" style="float:right" class="mdyuser-close"><img src="/resource/images/close.png" style="border:none;vertical-align: middle;"/></a>
        </div>
        <div style="clear: both"></div>
        <div>
            <p><span style="width: 96px;text-align: right;"><?= lang('tip_realname') ?>：</span><input type="text" name="txtRealName" id="txtRealName" value="" placeholder="<?= lang('tip_realname') ?>"/>&nbsp;<label class="tipps"></label>
            </p>
            <p><span style="width: 96px;text-align: right;"><?= lang('tip_repwd') ?>：</span><input type="text" name="txtRePwd" id="txtRePwd" value="" placeholder="<?= lang('tip_repwd_tips') ?>"/>
            </p>
            <p><span style="width: 96px;text-align: right;"><?= lang('tip_mail') ?>：</span><input type="text" name="txtEmail" id="txtEmail" value="" placeholder="<?= lang('tip_mail') ?>"/>&nbsp;<label class="tipps"></label></p>
            <p><span style="width: 96px;text-align: right;"><?= lang('tip_dept') ?>：</span><input type="text" name="txtDepartment" id="txtDepartment" value="" placeholder="<?= lang('tip_dept') ?>"/>&nbsp;<label class="tipps"></label></p>
            <p>
            <span style="width: 96px;text-align: right;overflow: visible;"><?= lang('tip_join') ?>：</span>
            <select  id="franchisees_id" name="franchisees_id" style="width: 200px;">
                <option value="">-请选择-</option>
                <?php foreach($joinList as $row){?>
                    <option value="<?=$row['id']?>"><?=$row['name']?></option>
                <?php }?>
            </select>
            &nbsp;<label class="tipps"></label>
            </p>
            <p><span style="width: 96px;text-align: right;"><?= lang('tip_hadper') ?>：</span><label class="tipsrole"></label><br/>
                <?php foreach ($rolelist as $v) { ?>
                <span><input type="checkbox" value="<?= $v['id'] ?>" name="cbkRole" id="cbk_<?= $v['id'] ?>"/><label for="cbk_<?= $v['id'] ?>" style="font-weight: normal;"><?= $v['name_ch'] ?>[<?= $v['name_en'] ?>]</label> </span>
                <?php } ?>
            </p>
            <p>
                <input type="button" value="<?= lang('tip_submit') ?>" class="btn-mdyuser">
                <input type="hidden" value="" id="hidUid"/>
            </p>
        </div>
    </div>


</div>





<style type="text/css">
    .mdyuser {
        width: 380px;

        background: #fff;
        padding: 13px 21px;
        box-shadow: 0 0 3px #000;
        position: fixed;
        top: 50%;
        left: 50%;
        margin: -201px 0 0 -120px;
    }

    .mdyuser p {
        line-height: 30px;
    }

    .mdyuser p span {
        width: 50%;
        float: left;
    }

    .btn-mdyuser {
        float: right;
        margin-right: 20px;
    }

    .mdy_user_title {
        width: 100%;
        line-height: 35px;
        border-bottom: 1px solid #e3e3e3;
        display: inline-block;
        background-color: white;
        margin-bottom: 10px;
    }

    .tipps, .tipsrole {
        color: #db3652
    }
</style>
<script type="text/javascript">
    $('.edituser').click(function () {
        $('.mdyuser').show();

        var indexx = $('.edituser').index($(this));//获取当前的的索引值
        var obj = $('.moves').eq(indexx).find('td');//根据索引的行数，获取到td对象
        $('#txtRealName').val(obj.eq(1).text());//真实姓名，下标为0，则是取当前行的第2个td
        $('#txtEmail').val(obj.eq(4).text());//电子邮箱地址，下标为4，则是取当前行的第5个td
        $('#txtDepartment').val(obj.eq(3).text());//部门，下标为3，则是取当前行的第4个td
        $('#hidUid').val($(this).attr('data-id'));//电子邮箱地址，下标为4，则是取当前行的第5个td
        $('#franchisees_id').val($(this).attr('data-join'));
        setRole($(this).attr('data-role'));
    });

    //这里是“关闭”修改用户信息框的处理
    $('.mdyuser-close').click(function () {
        $('.mdyuser input[type="text"]').val('');//清空所有input的值
        $('.mdyuser input[type="checkbox"]').prop('checked', false);//所有权限清空
        $('#hidUid').val(0);//清理用户id
        $('.mdyuser').hide();//隐藏弹出层
    });


    //提交事件
    $('.btn-mdyuser').click(function () {
        //非空验证
        var issubmit = true;
        $('.mdyuser input[type="text"]').each(function () {
            if ($(this).attr('id') != 'txtRePwd' && $.trim($(this).val()) == '') {
                //alert("不能为空");
                $(this).focus();
                $(this).next().text("<?= lang('not_null') ?>");
                issubmit = false;
            }
        });

        //以下拼接权限
        var chenked = $(".mdyuser input[type='checkbox']:checked").val([]);//此为重点
        var rids = "";//权限
        for (var i = 0; i < chenked.length; i++) {
            rids += chenked[i].value + ",";
        }
        //alert(rids);
        if (rids == '') {
            $('.tipsrole').text("<?=lang('not_per')?>");
            issubmit = false;
        }


        //如果验证都没有错误才能提交
        if (issubmit) {

            $('.mdyuser').hide();//隐藏弹出层
            var uri = '<?= blang_url('users/member/ajaxEditUser')?>';
            var uid = $('#hidUid').val();//用户id
            var uname = $.trim($('#txtRealName').val());//真实姓名
            var pwd = $.trim($('#txtRePwd').val());
            var email = $.trim($('#txtEmail').val());
            var dept = $.trim($('#txtDepartment').val());//部门
            var franchisees_id= $('#franchisees_id').val();
            $.ajax({
                type: "POST",
                url: uri,
                data: {
                    'uid': uid,
                    'uname': uname,
                    'pwd': pwd,
                    'email': email,
                    'dept': dept,
                    'rids': rids,
                    'franchisees_id':franchisees_id
                },
                dataType: "text",
                success: function (data) {
                    //成功的函数
                    if (data > 0) {
                        layer.msg("<?=lang('scccess')?>");
                        setTimeout(function () {
                            window.location.reload(true);
                        }, 600);

                    }
                }
            });
        }


    });

    /**
     * 设置权限复选框选中拥有的权限
     */
    function setRole(roleids) {
        var words = roleids.split(',')
        $('.mdyuser input[type="checkbox"]').each(function () {

            if ($.inArray($(this).val(), words) > -1) {
                $(this).prop("checked", true);
            }
        });
    }

    //维修师的角色验证，在老订单的流程中，维修师不能同时是客服、质检、QC
    $('#cbk_5').click(function () {
        if ($(this).is(':checked')) {
            if ($('#cbk_2').is(':checked') || $('#cbk_4').is(':checked') || $('#cbk_6').is(':checked'))
                layer.msg("<?=lang('no_service_qc')?>");
        }
    });
    $('#cbk_2,#cbk_4,#cbk_6').click(function () {
        if ($('#cbk_5').is(':checked')) {
            if ($('#cbk_2').is(':checked') || $('#cbk_4').is(':checked') || $('#cbk_6').is(':checked')) {
                layer.msg("<?=lang('no_service_qc')?>");
            }
        }
    });

</script>